<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<script type="text/javascript">
    var rowId = 0;
    
    $('.ui-reset , #refresh_loanGrid').click(function(){
        $("#loanGrid").jqGrid('setGridParam',{search:false});
        var postData = $("#loanGrid").jqGrid('getGridParam','postData');
        $.extend(postData,{searchField:"",searchString:"",searchOper:""});
        $.extend(postData,{filters:""});
        $("#loanGrid").trigger("reloadGrid");
    });

    $.subscribe('searchLoanGrid', function(event,data) {
        $("#loanGrid").jqGrid('searchGrid', {multipleSearch:true,drag:true,closeAfterSearch:true,closeOnEscape:true,sopt:['eq'],caption:"Search Loans"} );
    });
    
    $.subscribe('loanGridComplete',function(event,data){
        $( "#loanGrid_search" ).button( "option", "disabled", false );
        $( "#loanGrid_showhide" ).button( "option", "disabled", false );
    });
    
    $.subscribe('showhideLoanGrid', function(event,data) {
        $("#loanGrid").jqGrid('setColumns',{});
    });
    
</script>
<div class="gridOptsContainer">
    <sj:submit button="true" cssStyle="font-size:14px;" disabled="true" id="loanGrid_search" onClickTopics="searchLoanGrid" value="Search Loans"/>
    <sj:submit button="true" cssStyle="font-size:14px;" disabled="true" id="loanGrid_showhide" onClickTopics="showhideLoanGrid" value="Show/Hide Columns"/>
</div>

<s:if test="%{#request['borrowerid'] != null}">
    <s:url id="remoteurl" action="grid-loans">
        <s:param name="borrowerid" value="%{#request['borrowerid']}"/>
    </s:url>
</s:if>
<s:if test="%{#request['borrowerid'] == null}">
    <s:url id="remoteurl" action="grid-loans"/> 
</s:if>

<sjg:grid
    id="loanGrid"
    caption="Cashmate Loans"
    dataType="json"
    href="%{remoteurl}"
    gridModel="gridModel"
    pager="true"
    pagerButtons="true"
    pagerInput="true"
    rowList="15,30,50"
    rowNum="15"
    loadingText="Requesting Data..."
    width="970"
    shrinkToFit="false"
    hoverrows="true"
    rownumbers="true"
    autoencode="true"
    viewrecords="true"
    navigator="true"
    navigatorAdd="false"
    navigatorDelete="false"
    navigatorEdit="false"
    navigatorSearch="true"
    navigatorSearchOptions="{multipleSearch:true}"
    navigatorView="true"
    onGridCompleteTopics="loanGridComplete"
    >

    <sjg:gridColumn name="loanid"
                    key="true"
                    index="loanid"
                    title="loanid. (Not Editable)"
                    sortable="false"
                    hidden="true"
                    align="center"
                    />

    <sjg:gridColumn name="areacode"
                    index="areacode"
                    title="Areacode"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="documentno"
                    index="documentno"
                    title="Document No."
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="borrowercode"
                    index="borrowercode"
                    title="Borrower"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    sortable="true"
                    align="center"
                    />

    <sjg:gridColumn name="loanappdocumentno"
                    index="loanappdocumentno"
                    title="Loan Application Document"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="dateapproved"
                    index="dateapproved"
                    title="Date Approved"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="releasedate"
                    index="releasedate"
                    title="Release Date"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="startofamort"
                    index="startofamort"
                    title="Start of Amortization"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="status"
                    index="status"
                    title="Status"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="loanamount"
                    index="loanamount"
                    title="Loan Amount"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="netloanableamount"
                    index="netloanableamount"
                    title="Net Loanable Amount"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="amortizationperday"
                    index="amortizationperday"
                    title="Amortization per day"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="overdue"
                    index="overdue"
                    title="Overdue"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="balance"
                    index="balance"
                    title="Balance"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="term"
                    index="term"
                    title="Term"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="modeofpayment"
                    index="modeofpayment"
                    title="Mode of Payment"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="voucherprint"
                    index="voucherprint"
                    title="Voucher Print"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="checkprint"
                    index="checkprint"
                    title="Check Print"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />

    <sjg:gridColumn name="acknowledgementprint"
                    index="acknowledgementprint"
                    title="Acknowledgement Print"
                    sortable="true"
                    search="true"
                    searchoptions="{sopt:['eq']}"
                    align="center"
                    />
</sjg:grid>
